package com.pipodi.itasamobile.connections;

import java.io.IOException;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;

public abstract class HttpAbstract {

	protected DefaultHttpClient client;
	protected HttpResponse response;
	protected HttpEntity entity;
	protected HttpGet get;
	protected String namefile;

	HttpAbstract() {
		this.client = new DefaultHttpClient(new BasicHttpParams());
	}

	HttpAbstract(int timeout) {
		HttpParams my_httpParams = new BasicHttpParams();
		HttpConnectionParams.setConnectionTimeout(my_httpParams, timeout);
		HttpConnectionParams.setSoTimeout(my_httpParams, timeout);
		this.client = new DefaultHttpClient(my_httpParams);
	}

	public String getNameFile() {
		return this.namefile;
	}

	public void closeClient() {
		this.client.getConnectionManager().shutdown();
	}

	protected void consumeEntity() throws IOException {
		if (this.entity != null) {
			this.entity.consumeContent();
		}
	}

	public abstract HttpEntity requestGetEntity(String paramString)
			throws IndexOutOfBoundsException, IOException;

	protected abstract void getAttachement(Header[] paramArrayOfHeader,
			String paramString) throws IndexOutOfBoundsException;
}
